<style lang="sass" scoped>
    .main{
        margin:30px 0 10px 30px;
        h1{
            font-size:28px;
        }
        h2{
            font-size:22px;
            display:inline-block;
        }
        .giz{
            padding-left:45px;
        }
    }
    .font-weight{
        font-weight:bold;
        font-size:20px;
        margin-bottom:10px;
    }
    .http-push-input{
        height:45px;        
    }
</style>

<template>
<div class="container-fluid">
    <div class="main">
        <h1>正式环境其他内容发布</h1>
        <hr>
        <div class="contentmain">
            <!-- 选择公司 -->
            <h2>选择公司：</h2>
            <select v-model="company" class="form-control w-150 inline_block mr20">
                <option :value="{}">请选择公司</option>
                <option 
                    v-Jurisdiction="item.onlineAcCode" 
                    v-for="item in sysList" 
                    :value="item">{{ item.companyName }}</option>
            </select>
            <hr>

            <div class="mb30">
                <hr>
                <p class="font-weight">文件解压路径： <b>{{options.data.base}}</b> </p>
                <p><input type="text" class="form-control w-400 http-push-input" v-model="options.data.base"></p>
                <hr>
                <p class="ml10 red mt20">备注： <b>此功能不懂者不要随便使用</b> </p> 
                <p class="ml10 red ">备注： <b>上传文件必须为 .zip 包，解压包名字默认为发布文件夹, 此处可以发布系统代码，也可以发布活动或者官网，或者其他 ...</b> </p> 
                <p class="ml10 lightcolor giz"></p> 
            </div>          
            <drop v-if="isShow" :options="options" :callback="callback"></drop>

        </div>
    </div>
</div>
</template>

<script>
    import drop from 'components/drop'
    export default {
        components: {
           drop
        },
        data(){
            return {
                sysList:[],
                company:{},
                isShow:true,
                options:{
                    url:'',
                    checktype:['zip'],
                    boxSize:'lg',
                    data:{
                        pushtype:'another',
                        base:'/usr/local/nginx/',
                        getSign:JSON.stringify(util.getSignData()),
                    },
                },
                headInfo:util.getStorage('session','headerInfo')?JSON.parse(util.getStorage('session','headerInfo')):{},
                fileDir:'',
                pushResult:'',
                pushTime:'',
            }
        },
        watch:{
            "company"(){
                this.options.url =this.company.onlineAcHttpSrc;
                if(this.options.url&&this.options.data.base){
                    this.isShow=true; 
                }else{
                    this.isShow=false; 
                } 
            }
        },
        mounted() {
            this.$nextTick(()=>{
                this.getCompanyList()
            })
        },
        methods: {
            // 获得公司列表
            getCompanyList(){
                util.ajax({
                    url:config.baseApi+'api/getComSysDataList',
                    success:data=>{
                        this.sysList = data.data;
                    }
                })
            },

            //发布
            callback(data,fileDir){
                console.log(data)
                if(data.code == 1000){
                    this.pushResult = 0
                }else{
                    this.pushResult = 1
                };
                this.pushTime = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')

                this.fileDir = fileDir;
                if(this.company.receiveEmail){this.sendEmail();}
                this.pushSysLogs();
            },

            // 发送邮件
            sendEmail(){
                util.ajax({
                    url:config.baseApi+'api/sendEmail',
                    data:{
                        user:this.headInfo.realName,
                        sysName:this.company.companyName,
                        sysCode:this.company.companyCode,
                        receiveEmail:this.company.receiveEmail,
                        time:moment(new Date()).format('YYYY/MM/DD HH:mm:ss'),
                        successStr:'活动发布成功!',
                        fileDir:this.fileDir,
                        onlineAcServerDir:this.company.onlineAcServerDir,
                    },
                    success:data=>{
                        if(data.data.messageId&&data.data.response){
                            popup.alert({title:'活动发送成功！<br/> 邮件发送成功!'})
                        }else{
                            popup.alert({title:'活动发送成功！'})
                        };
                    }
                })
            },
            // 发布记录
            pushSysLogs(){
                util.ajax({
                    url:config.baseApi+'api/pushSysLogs',
                    data:{
                        pushUser:this.headInfo.realName,
                        pushType:1,
                        pushSystem:`发布：${this.fileDir}活动`,
                        pushResult:this.pushResult,
                        pushTime:this.pushTime,
                        companyCode:this.company.companyCode,
                        companyName:this.company.companyName,
                        systemType:0,
                    },
                    success:data=>{
                        popup.alert({title:'活动发送成功！'})
                    }
                })
            },

        }
    }

</script>






